﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NTerm;
using System.Threading;

namespace NTermConsole
{
    public static class Tests
    {
        public static void SimpleWriteTestA()
        {
            NTerminal.WriteLine("Welcome to NTerminal! This was printed using the NTerm library.");
        }

        public static void BufferFillTestA()
        {
            Random rnd = new Random(System.Environment.TickCount);
            int enumLength = Enum.GetNames(typeof(ConsoleColor)).Length;
            int colv = rnd.Next(enumLength);

            for (int i = 0; i < NTerminal.BufferWidth * NTerminal.BufferHeight; i+=2)
            {
                if (i == NTerminal.BufferWidth * NTerminal.BufferHeight - 2)
                {
                    NTerminal.Write("$$");
                    NTerminal.ForegroundColor = ConsoleColor.Cyan;
                    NTerminal.Write("-> Will redraw buffer in 5 seconds");
                    NTerminal.ResetColor();
                    Thread.Sleep(5000);
                }
                else
                {
                    colv = rnd.Next(enumLength);
                    NTerminal.BackgroundColor = (ConsoleColor)colv;
                    NTerminal.ForegroundColor = (ConsoleColor)((enumLength - 1) - colv);
                    NTerminal.Write("++");
                    NTerminal.ResetColor();
                }
            }

            NTerminal.ForceConsoleRefresh();
            NTerminal.ClearLine();
        }

        public static void SimpleScrollA()
        {
            NTerminal.Write("Cookies are yummy\nBread is good too\nPress ENTER to scroll the text up by one line");
            NTerminal.ReadLine();
            NTerminal.ScrollBuffer(1, false);
            NTerminal.ForceConsoleRefresh();
        }

        public static void FormattedStringA()
        {
            NTerminal.WriteLine("{0} is number {1}", new object[] { "NTerm", 1 });
        }

        public static void ControlCharsA()
        {
            NTerminal.Write("Text\nNewline\n");
            NTerminal.Write("xyz\rCarriage Return\nBackspace\bE\n");
            NTerminal.Write("\tTabbed Word\n");
        }

        public static void SimpleTabbingA()
        {
            NTerminal.BackgroundColor = ConsoleColor.Red;

            for (int i = 0; i < ((NTerminal.BufferWidth / 8) + 1); i++)
                NTerminal.Write("\t");

            NTerminal.ResetColor();
        }

        public static void AdvancedTabbingA()
        {
            NTerminal.BackgroundColor = ConsoleColor.DarkRed;
            NTerminal.Write("breadtzs");
            NTerminal.BackgroundColor = ConsoleColor.Red;
            NTerminal.WriteLine("\t");
            NTerminal.BackgroundColor = ConsoleColor.Cyan;
            NTerminal.Write("cookie");
            NTerminal.CursorLeft = 3;
            NTerminal.BackgroundColor = ConsoleColor.Red;
            NTerminal.Write("\t");
            NTerminal.ResetColor();
            NTerminal.BackgroundColor = ConsoleColor.Yellow;
            NTerminal.Write("\nbread");
            NTerminal.BackgroundColor = ConsoleColor.Red;
            NTerminal.Write("\t\t");
            NTerminal.ResetColor();
            NTerminal.Write("\n12345678");
            NTerminal.ForceConsoleRefresh();
        }

        public static void TestExceptionsA()
        {
            NTerminal.Shutdown();

            try
            {
                NTerminal.Clear();
                NTerminal.WriteLine("Exception didnt throw. Report this.");
            }
            catch (NTerm.InitializationException)
            {
                NTerminal.Initialize();
                NTerminal.WriteLine("The Exception has successfully been thrown");
            }
        }
    }
}
